package com.ruoyi.customerSample.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.customerSample.domain.Customer;
import com.ruoyi.customerSample.service.ICustomerService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 受检单位信息Controller
 * 
 * @author luguanqing
 * @date 2020-11-10
 */
@RestController
@RequestMapping("/custSam/customer")
@Api(value="受检单位",tags = "受检单位接口")
public class CustomerController extends BaseController
{
    @Autowired
    private ICustomerService reportCompanyService;

    /**
     * 查询受检单位信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value="查询受检单位信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(Customer reportCompany)
    {
        startPage();
        List<Customer> list = reportCompanyService.selectReportCompanyList(reportCompany);
        return getDataTable(list);
    }


    /**
     * 查询受检单位信息列表
     */
    @GetMapping("/list/all")
    @ApiOperation(value="查询受检单位所有信息")
    public AjaxResult listAll(Customer reportCompany)
    {
        List<Customer> list = reportCompanyService.selectReportCompanyList(reportCompany);
        return AjaxResult.success(list);
    }

    /**
     * 导出受检单位信息列表
     */
    @Log(title = "受检单位信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Customer reportCompany)
    {
        List<Customer> list = reportCompanyService.selectReportCompanyList(reportCompany);
        ExcelUtil<Customer> util = new ExcelUtil<Customer>(Customer.class);
        return util.exportExcel(list, "company");
    }

    /**
     * 获取受检单位信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取受检单位信息详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(reportCompanyService.selectReportCompanyById(id));
    }

    /**
     * 新增受检单位信息
     */
    @Log(title = "受检单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增受检单位信息")
    public AjaxResult add(@ApiParam(name="受检单位信息",value="传入json格式",required=true)@RequestBody Customer reportCompany)
    {
        reportCompany.setId(IdUtils.fastSimpleUUID());
        return toAjax(reportCompanyService.insertReportCompany(reportCompany));
    }

    /**
     * 修改受检单位信息
     */
    @Log(title = "受检单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改受检单位信息")
    public AjaxResult edit(@ApiParam(name="受检单位信息",value="传入json格式",required=true)@RequestBody Customer reportCompany)
    {
        return toAjax(reportCompanyService.updateReportCompany(reportCompany));
    }

    /**
     * 删除受检单位信息
     */
    @Log(title = "受检单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除受检单位信息")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(reportCompanyService.deleteReportCompanyByIds(ids));
    }
}
